package component
{
	import mx.containers.Canvas;
	import mx.core.UIComponent;
	
	public class TopAlertInfo extends Canvas
	{
		private var ary:Vector.<TxtInfoItem>;
		private var ui:UIComponent;
		public function TopAlertInfo()
		{
			super();
			ary = new Vector.<TxtInfoItem>;
			ui = new UIComponent;
			this.addChild(ui);
		}
		public function addAlert(str:String,key:String):void{
			this.visible = true;
			for(var i:int;i<ary.length;i++){
				if(ary[i].key == key){
					ary[i].info = str;
					ary[i].txt.text = str;
					break;
				}
			}
			if(i == ary.length){
				var obj:TxtInfoItem = new TxtInfoItem;
				obj.info = str;
				obj.key = key;
				obj.txt.text = str;
				obj.txt.x = (this.width - obj.txt.width)/2;
				obj.txt.y = 240 + i*30;
				ui.addChild(obj.txt);
				ary.push(obj);
			}
		}
		public function removeAlert(key:String):void{
			for(var i:int;i<ary.length;i++){
				if(ary[i].key == key){
					if(ary[i].txt.parent){
						ary[i].txt.parent.removeChild(ary[i].txt);
					}
					ary.splice(i,1);
					break;
				}
			}
			if(ary.length == 0){
				this.visible = false;
			}
		}
		
	}
}